package com.ycd.Servlet;

import com.ycd.Entity.Page;
import com.ycd.Entity.UserEntity;
import com.ycd.Service.UserEntityService;
import com.ycd.Service.impl.UserEntityServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description: 登录页面的展示
 * @Author: ycd
 * @Date : 2022/3/16 16:08
 * @Version : 1.0
 * @company 新开普电子股份有限公司
 */

@WebServlet("/AccountManagement.html")
public class ShowAccountHtmlServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            req.setCharacterEncoding("utf-8");
            resp.setCharacterEncoding("utf-8");


        Page page=new Page();
        UserEntityService sysUserService=new UserEntityServiceImpl();
        //设置总条数到page类中
        page.setTotal(sysUserService.getAllCont());

        //获取用户传递过来的参数
        String pageNum=req.getParameter("pageNum");

        if(pageNum!=null){
            page.setPageNum(Integer.parseInt(pageNum));
        }else{
            page.setPageNum(1);
        }
        page.setPageSize(3);


        List<UserEntity> sysUsers= sysUserService.queryAll(page.getOffset(),page.getPageSize(),null);



        req.setAttribute("page",page);
        req.setAttribute("list",sysUsers);




        req.getRequestDispatcher("WEB-INF/page/AccountManagement.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
